package com.person.android.domain;

/**
 * @autor zhaokang.
 * @time on 2015/12/19.
 */
public class SendEmailTask {

    private SendRunnable mSendRunnable;
    private TimeRunnable mTimeRunnable;

    private boolean mShouldPauseSend = false;   //是否应当暂停发送

    private boolean mIsWaiting = false;
    private String mEmailInfo;                  //要发送的信息

    public SendEmailTask(String emailInfo) {
        this.mEmailInfo = emailInfo;
    }

    //发送线程
    private final class SendRunnable implements Runnable {
        @Override
        public void run() {
            //网络发送邮件
            if (!mShouldPauseSend) {

            }
        }
    }

    private final class TimeRunnable implements Runnable {
        @Override
        public void run() {
            try {
                int timeWait = 0;
                while (mIsWaiting) {
                    Thread.sleep(1000);
                    timeWait++;
                    if (timeWait > 6) {
                        break;
                    }
                }

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void start() {
        mIsWaiting = true;
        mShouldPauseSend = false;
        mSendRunnable = new SendRunnable();
        mTimeRunnable = new TimeRunnable();
        new Thread(mSendRunnable).start();
        new Thread(mTimeRunnable).start();
    }

    public void stop() {
        mIsWaiting = false;
        mShouldPauseSend = true;
    }

}
